package com.marshall.shardingjdbc.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.marshall.shardingjdbc.entity.Course;
import com.marshall.shardingjdbc.mapper.CourseMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by
 *
 * @author : Marshall
 * @datetime: 2021/12/24 16:22
 */
@RestController
@RequestMapping("/course")
public class CourseController {

    @Autowired
    private CourseMapper courseMapper;


    @PostMapping("/add")
    public String insertCourse(){
        Course course = new Course();
        course.setCname("java");
        course.setUserId(100L);
        course.setCstatus("Normal");
        int i = courseMapper.insert(course);
        return i+"";
    }

    @GetMapping("/getOne")
    public Course getCourse(){
        QueryWrapper<Course> courseQueryWrapper = new QueryWrapper<Course>().eq("cid",681185697612169217L);
        Course course = courseMapper.selectOne(courseQueryWrapper);
        return course;
    }
}
